/*
 * Copyright (c) 2006, 2021, webrx.cn All rights reserved.
 *
 */
package cn.reflection;

import java.lang.reflect.Method;

/**
 * <p>Project: javaseapp - Ref2
 * <p>Powered by webrx On 2021-08-30 15:18:33
 * <p>Created by IntelliJ IDEA
 *
 * @author webrx [webrx@126.com]
 * @version 1.0
 * @since 16
 */
public class Ref2 {
    public static void main(String[] args) {
        String c = "cn.reflection.User";
        try {
            //相当于 var u = new User();
            //利用反射动态加载指定的类，来实实例化，并调用
            var u = Class.forName(c);
            //实例化
            //User u2 = (User) u.getConstructor().newInstance();
            //System.out.println(u2.pf(19));

            var u2 = u.getConstructor().newInstance();
            System.out.println(u);
            System.out.println(u2);
            System.out.println(u2 == u);
            Method pf = u.getMethod("pf", int.class);
            System.out.println(pf.invoke(u2, 3));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
